package com.iis.databaseutil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnection {

	private static Connection myDataConnection;

	private static final String DATABASE_URL = "jdbc:mysql://localhost:3306/iis_database_2";

	public static Connection getDataConnection(boolean isAutoCommit) {
		if (myDataConnection == null) {
			try {
				Class.forName("com.mysql.jdbc.Driver").newInstance();
				myDataConnection = DriverManager.getConnection(DATABASE_URL,
						"root", "");
				myDataConnection.setAutoCommit(true);
			} catch (SQLException e) {
				e.printStackTrace();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			try {
				myDataConnection.setAutoCommit(isAutoCommit);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return myDataConnection;
	}
	
	public static Connection getDataConnection(){
		return getDataConnection(true);
	}

}
